#!/bin/bash
# Author: Francesco Montorsi <frm@users.sourceforge.net>

rootdir=../..
thisdir=distrib/autopackage
currloc="http://biolpc22.york.ac.uk/pub/autopackage/wxgtk/"

function reminder
{
    echo = REMINDER ===================================================
    echo Now that the autopackage has been built successfully, remember
    echo to upload the .meta, .package and .xml files to the
    echo "    $currloc"
    echo folder.
    echo ==============================================================
}

function build_package
{
    me=`basename $0`
    cd $rootdir
    if [[ ! -f "config.status" ]]; then
        echo $me: Running a fake configure just to create a config.status
        echo $me: with a valid PACKAGE_VERSION set... please wait.
        ./configure >/dev/null 2>&1
    fi

    if [[ "$1" = "--help" ]]; then
        makeinstaller $@
        exit 0
    fi

    # this will automatically update wxgtk.apspec from wxgtk.apspec.in
    # using config.status script
    makeinstaller $@ $thisdir/wxgtk.apspec

    if [[ "$?" = "0" ]]; then
        mv *.package *.xml *.meta $thisdir >/dev/null 2>&1
        reminder
    fi
}

function clean_previous
{
    rm -f wxgtk.apspec     # this was generated from wxgtk.apspec.in
    rm -f *.xml *.package *.meta
}


clean_previous
build_package $@
